package subapp

import (
	"fmt"

	"gitee.com/kobeyyf/apibox/api"
	"gitee.com/kobeyyf/apibox/handler"
)

func NewApp() (*api.Api, error) {
	app, err := api.NewAPI("sub_app/config.yaml")
	if err != nil {
		return nil, err
	}

	app.AddHandles(map[string]handler.HandlerFunc{
		"sub.hello":  HelloHandle,
		"Say.Hello2": HelloHandle,
		"Say.Hello3": HelloHandle3,
	})
	// app.Before(mid)
	return app, nil
}

func HelloHandle(c *handler.Context) *handler.Response {
	// c.JSON(200, "hello, world from sub app")
	return handler.NewSuccessResponse("sub app")
}
func HelloHandle3(c *handler.Context) *handler.Response {
	// c.JSON(200, "hello, world from sub app")
	fmt.Println("xxxxx")
	var a []string
	a[0] = "1"
	return handler.NewSuccessResponse("sub app")

}

func mid(c *handler.Context) *handler.Response {
	c.ResponseWriter.Write([]byte("for midde"))
	return nil
}
